<?php

/**
 * This is the model class for table "mms_exam".
 *
 * The followings are the available columns in table 'mms_exam':
 * @property integer $examID
 * @property integer $possible
 * @property integer $possibleless
 * @property string $examDate
 * @property string $examTime
 * @property string $examRoom
 * @property string $floor
 * @property string $examResult
 * @property string $resultDate
 * @property string $criteria
 * @property string $description
 * @property string $creatUser
 * @property string $createDate
 * @property string $updateUser
 * @property string $updateDate
 * @property integer $projectID
 *
 * The followings are the available model relations:
 * @property Committee[] $committees
 * @property Project $project
 */
class Exam extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mms_exam';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('examDate', 'required','message'=>'กรุณากรอกข้อมูล {attribute}'),
			array('possible, possibleless, projectID', 'numerical', 'integerOnly'=>true),
			array('examRoom', 'length', 'max'=>150),
			array('floor', 'length', 'max'=>45),
			array('examResult, criteria', 'length', 'max'=>4),
			array('creatUser, updateUser', 'length', 'max'=>20),
			array( 'examTime, resultDate, description, createDate, updateDate', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('examID, possible, possibleless, examDate, examTime, examRoom, floor, examResult, resultDate, criteria, description, creatUser, createDate, updateUser, updateDate, projectID', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'committees' => array(self::HAS_MANY, 'Committee', 'examID'),
			'project' => array(self::BELONGS_TO, 'Project', 'projectID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'examID' => 'รหัสผลสอบ',
			'possible' => 'มีความเป็นไปได้',
			'possibleless' => 'มีความเป็นไปได้น้อย',
			'examDate' => 'วันที่สอบ',
			'examTime' => 'เวลาที่สอบ',
			'examRoom' => 'ห้องสอบ',
			'floor' => 'ชั้น',
			'examResult' => 'ผลการสอบ',
			'resultDate' => 'วันประกาศผล',
			'criteria' => 'เงื่อนไข',
			'description' => 'ความคิดเห็น',
			'creatUser' => 'ผู้บันทึก',
			'createDate' => 'วันที่บันทึก',
			'updateUser' => 'ผู้ปรับปรุงข้อมูล',
			'updateDate' => 'วันที่ปรับปรุงข้อมูล',
			'projectID' => 'รหัสโครงการสารนิพนธ์',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('examID',$this->examID);
		$criteria->compare('possible',$this->possible);
		$criteria->compare('possibleless',$this->possibleless);
		$criteria->compare('examDate',$this->examDate,true);
		$criteria->compare('examTime',$this->examTime,true);
		$criteria->compare('examRoom',$this->examRoom,true);
		$criteria->compare('floor',$this->floor,true);
		$criteria->compare('examResult',$this->examResult,true);
		$criteria->compare('resultDate',$this->resultDate,true);
		$criteria->compare('criteria',$this->criteria,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('creatUser',$this->creatUser,true);
		$criteria->compare('createDate',$this->createDate,true);
		$criteria->compare('updateUser',$this->updateUser,true);
		$criteria->compare('updateDate',$this->updateDate,true);
		$criteria->compare('projectID',$this->projectID);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Exam the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
